//
//  BBMainBarVC.swift
//  BaoKanSwift
//
//  Created by uncle-R on 16/6/8.
//  Copyright © 2016年 uncle-R. All rights reserved.
//

import UIKit

class BBMainBarVC: UITabBarController {
    
    let imagenName = ["tabbar_icon_news_normal@2x.png","tabbar_icon_media_normal@2x","tabbar_icon_me_normal@2x"]
    let selectedName = ["tabbar_icon_news_highlight@2x","tabbar_icon_media_highlight@2x","tabbar_icon_me_highlight@2x"]
    let titles = ["资讯","图秀","我"]
    
     // MARK: - 生命周期
    override func viewDidLoad() {
        super.viewDidLoad()
        setupChildVC()
        view.backgroundColor = UIColor.whiteColor()
        
    }

     // MARK: -  =============================Method================================
    func setupChildVC() {
        
        self.tabBar.tintColor = UIColor.redColor()//设置选中文字的颜色(统一样式)
        
        let v1 = InfomationController()
        addToChildVC(v1, title: titles[0], normalImageName: imagenName[0], selectedImageName: selectedName[0])
        
        let v2 = PictureController()
        addToChildVC(v2, title: titles[1], normalImageName: imagenName[1], selectedImageName: selectedName[1])
        
        let v3 = MineController()
        addToChildVC(v3, title: titles[2], normalImageName: imagenName[2], selectedImageName: selectedName[2])
    }
    
    func addToChildVC(vc:UIViewController ,title:String, normalImageName:String ,selectedImageName:String ) -> Void {

        let nav = BBNavigationController(rootViewController: vc)
        vc.tabBarItem.title = title
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(12)], forState: UIControlState.Normal)
        vc.tabBarItem.image = UIImage(named: normalImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named:selectedImageName)!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        addChildViewController(nav)

    }

}
